import request from '@/utils/request'
import { praseStrEmpty } from "@/utils/ruoyi";

// 查询用户列表
export function listUser(query) {
    return request({
        url: '/permission/user/',
        method: 'get',
        params: query
    })
}

// 查询用户详细
export function getUser(userId) {
    return request({
        url: '/permission/user/' + praseStrEmpty(userId) + '/',
        method: 'get'
    })
}

// 新增用户
export function addUser(data) {
    return request({
        url: '/permission/user/',
        method: 'post',
        data: data
    })
}
//注册用户
export function registerUser(data) {
    return request({
        url: '/permission/register/',
        method: 'post',
        data: data
    })
}
// 修改用户
export function updateUser(data) {
    return request({
        url: '/permission/user/' + data.id + '/',
        method: 'patch',
        data: data
    })
}

// 删除用户
export function delUser(userId) {
    return request({
        url: '/permission/user/' + userId + '/',
        method: 'delete'
    })
}

// 导出用户
export function exportUser(query) {
    return request({
        url: '/permission/user/export/',
        method: 'get',
        params: query
    })
}

// 管理员重置用户密码
export function resetUserPwd(data) {
    return request({
        url: '/permission/user/' + data.id + '/admin_reset_password/',
        method: 'post',
        data: data
    })
}

// 用户状态修改
export function changeUserStatus(id, is_active) {
    const data = {
        id,
        is_active
    }
    return request({
        url: '/permission/user/'+id+'/',
        method: 'put',
        data: data
    })
}

// 查询用户个人信息
export function getUserProfile(id) {
    return request({
        url: '/permission/user/' + id + '/',
        method: 'get'
    })
}

// 修改用户个人信息
export function updateUserProfile(data) {
    return request({
        url: '/admin/permission/user/profile/',
        method: 'put',
        data: data
    })
}

// 用户密码修改
export function updateUserPwd(data) {

    return request({
        url: '/permission/user/' + data.id + '/change-password/',
        method: 'post',
        data: data
    })
}


// 用户头像上传
export function uploadAvatar(data) {
    return request({
        url: '/permission/user/profile/avatar/',
        method: 'put',
        data: data
    })
}

// 下载用户导入模板
export function importTemplate() {
    return request({
        url: '/permission/user/importTemplate/',
        method: 'get'
    })
}

// 用户导入
export function importsUser(data) {
    return request({
        url: '/permission/user/importTemplate/',
        method: 'post',
        data: data
    })
}
// 更新用户
export function deptupdate() {
    return request({
        url: '/permission/DeptSync/',
        method: 'get',
    })
}